from django.db import models

from goods.models import Foods
from shops.models import ShopsModel
from user.models import UserModel, UserAddressModel


class OrderPModel(models.Model):
    order_id = models.IntegerField(primary_key=True, auto_created=True)
    user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING)
    shop = models.ForeignKey(ShopsModel, on_delete=models.DO_NOTHING)
    order_number = models.CharField(max_length=64)
    box_cost = models.DecimalField(max_digits=10, decimal_places=0)
    send_cost = models.DecimalField(max_digits=10, decimal_places=0, null=True)
    total_money = models.DecimalField(max_digits=10, decimal_places=0)
    discount_money = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    coupon_money = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    pay_money = models.DecimalField(max_digits=10, decimal_places=0)
    pay_way = models.IntegerField(default=1)
    demand_time = models.DateTimeField()
    created_time = models.DateTimeField()
    status = models.IntegerField(default=1)
    remark = models.CharField(max_length=1024)

    class Meta:
        managed = False
        db_table = 'order_p'


class OrderCommentModel(models.Model):
    order_comment_id = models.IntegerField(primary_key=True, auto_created=True)
    content = models.CharField(max_length=512, null=True)
    created_time = models.DateTimeField(blank=True, null=True)
    order = models.ForeignKey(OrderPModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    score = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'order_comment'


class OrderDetailModel(models.Model):
    order_detail_id = models.IntegerField(primary_key=True, auto_created=True)
    order = models.ForeignKey(OrderPModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    address = models.ForeignKey(UserAddressModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    user_username = models.CharField(max_length=32)
    user_mobile = models.CharField(max_length=32)
    user_address = models.CharField(max_length=256)
    user_longitude = models.CharField(max_length=32)
    user_latitude = models.CharField(max_length=32)
    shop_shopname = models.CharField(max_length=128)
    shop_mobile = models.CharField(max_length=32)
    shop_address = models.CharField(max_length=256)
    shop_longitude = models.CharField(max_length=32)
    shop_latitude = models.CharField(max_length=32)
    deliver_name = models.CharField(max_length=32, null=True)
    deliver_mobile = models.CharField(max_length=32, null=True)

    class Meta:
        managed = False
        db_table = 'order_detail'


class OrderFoodModel(models.Model):
    order_food_id = models.IntegerField(primary_key=True, auto_created=True)
    order = models.ForeignKey(OrderPModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    shop_id = models.IntegerField(blank=True, null=True)
    shop_name = models.CharField(max_length=128)
    food = models.ForeignKey(Foods, on_delete=models.DO_NOTHING, blank=True, null=True)
    food_name = models.CharField(max_length=128)
    cover = models.CharField(max_length=128)
    origin_price = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    shell_price = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    number = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'order_food'


class OrderRefundModel(models.Model):
    order_refund_id = models.IntegerField(primary_key=True)
    order = models.ForeignKey(OrderPModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    user_name = models.CharField(max_length=32)
    pay_money = models.DecimalField(max_digits=10, decimal_places=0)
    refund_reason = models.CharField(max_length=512, blank=True, null=True)
    apply_time = models.DateTimeField(blank=True, null=True)
    service_cost = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    handle_time = models.DateTimeField(blank=True, null=True)
    finish_time = models.DateTimeField(blank=True, null=True)
    status = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'order_refund'


class PayModel(models.Model):
    pay_id = models.IntegerField(primary_key=True)
    shop = models.ForeignKey(ShopsModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    user = models.ForeignKey(UserModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    order = models.ForeignKey(OrderPModel, on_delete=models.DO_NOTHING, blank=True, null=True)
    total_money = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    # (0 订单取消   1 未支付    2  已支付)
    status = models.IntegerField(blank=True, null=True)
    created_time = models.DateTimeField()
    deal_time = models.DateTimeField(null=True)

    class Meta:
        managed = False
        db_table = 'pay'


